package com.biz.primus.ms.homepage.api;

import com.biz.primus.homepage.vo.*;
import com.biz.primus.ms.base.api.BaseApiController;
import com.biz.primus.ms.homepage.service.CoverServerService;
import com.biz.primus.ms.homepage.service.ProgramServerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author jiangnan
 * @Description:
 */
@Api("首页后台接口")
@RestController
@RequestMapping("soa/homepageService")
public class HomePageBackendApiController extends BaseApiController {

    private final CoverServerService coverServerService;

    private final ProgramServerService programServerService;

    public HomePageBackendApiController(CoverServerService coverServerService, ProgramServerService programServerService) {
        this.coverServerService = coverServerService;
        this.programServerService = programServerService;
    }

    @ApiOperation("保存cover")
    @PostMapping("cover/save")
    public void saveCover(@RequestBody CoverUpdateVo reqVo) {
        coverServerService.saveCover(reqVo);
    }

    @ApiOperation("list cover")
    @GetMapping("cover/list")
    public List<CoverRoVo> listCover() {
        return coverServerService.findAll();
    }

    @ApiOperation("findone Cover")
    @GetMapping("cover/findOne")
    public CoverRoVo findOne(@RequestParam("coverId") String coverId) {
        return coverServerService.findOne(coverId);
    }

    @ApiOperation("getAllProgramsByCoverId")
    @GetMapping("getAllProgramsByCoverId")
    public List<ProgramRoVo> getAllProgramsByCoverId(@RequestParam("coverId") String coverId) {
        return programServerService.getAllProgramsByCoverId(coverId);
    }

    @ApiOperation("删除首页配置")
    @PostMapping("cover/delete")
    void deleteCover(@RequestBody CoverDeleteVo coverDeleteVo) {
        coverServerService.deleteCover(coverDeleteVo);
    }

    @ApiOperation("findone program")
    @GetMapping("program/findone")
    ProgramRoVo findOne(@RequestParam("programId") Long programId) {
        return programServerService.findOne(programId);
    }

    @ApiOperation("列出动态数据源")
    @GetMapping("cover/listCoverProvider")
    List<CoverProviderVo> listCoverProvider() {
        return coverServerService.listCoverProvider();
    }

    @ApiOperation("getProgramDetail")
    @GetMapping("program/getProgramDetail")
    ProgramDetailRespVo getProgramDetail(@RequestParam("programId") Long programId) {
        return programServerService.getProgramDetail(programId);
    }

    @ApiOperation("save program")
    @GetMapping("program/save")
    ProgramRoVo save(@RequestBody ProgramUpdateReqVo reqVo) {
        return programServerService.save(reqVo);
    }

    @ApiOperation("program delete")
    @GetMapping("program/delete")
    void delete(@RequestParam("programId") Long programId) {
        programServerService.delete(programId);
    }

    @ApiOperation("返回首页模板的克隆")
    @GetMapping("clone")
    public CoverWithPrograms clone(@RequestParam("coverId") String coverId) {
        CoverRoVo coverRo = coverServerService.findOne(coverId);
        List<ProgramRoVo> programs = programServerService.getAllProgramsByCoverId(coverId);
        return new CoverWithPrograms(coverRo, programs);
    }

    @ApiOperation("克隆首页模板")
    @PostMapping("doClone")
    CoverRoVo doClone(@RequestBody CoverWithPrograms coverWithPrograms,@RequestBody String clonedBy) {
        return coverServerService.doClone(coverWithPrograms,clonedBy);
    }


}
